package com.yc.snack.biz.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.yc.snack.biz.ITypeInfoBiz;
import com.yc.snack.dao.ITypeInfoDao;
import com.yc.snack.dao.impl.TypeInfoDaoImpl;
import com.yc.snack.entity.TypeInfo;
import com.yc.snack.util.StringUtil;

public class TypeInfoBizImpl implements ITypeInfoBiz {

	@Override
	public int add(TypeInfo tf) {
		if(StringUtil.checkNull(tf.getTname())) {
			return -1;
		}
		ITypeInfoDao typeInfoDao = new TypeInfoDaoImpl();
		return typeInfoDao.add(tf);
	}

	@Override
	public List<TypeInfo> finds() {
		ITypeInfoDao typeInfoDao = new TypeInfoDaoImpl();
		return typeInfoDao.finds();
	}

	@Override
	public Map<String, Object> findByPage(int page, int rows) {
		ITypeInfoDao typeInfoDao = new TypeInfoDaoImpl();
		List<TypeInfo> list = typeInfoDao.findByPage(page, rows);
		Map<String,Object> result = new HashMap<String,Object>();
		//list.isEmpty() 里面没有数据
		if(list == null || list.isEmpty()) {
			result.put("code", "600");
			result.put("msg", "暂无数据....");
			return result;
		}
		result.put("code", 0);
		result.put("data", list);
		result.put("count", typeInfoDao.getTotal());
		return result;
	}

}
